package cn.stylefeng.guns.modular.robot.controller;

import cn.stylefeng.guns.modular.robot.entity.CdInfo;
import cn.stylefeng.guns.modular.robot.entity.vo.req.OrderInfoReq;
import cn.stylefeng.guns.modular.robot.entity.vo.req.SubmitCdReq;
import cn.stylefeng.guns.modular.robot.entity.vo.resp.PullOrderResp;
import cn.stylefeng.guns.modular.robot.service.CdInfoService;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/cdInfo")
public class CdInfoController {

    @Resource
    private CdInfoService cdInfoService;

    @GetMapping("/getNewInfo")
    public List<CdInfo> getNewInfo() {
        return cdInfoService.lambdaQuery()
                .eq(CdInfo::getIsHandle, false)
                .orderByAsc(CdInfo::getCreateTime)
                .list();
    }

    @PostMapping("/cdNotify")
    public void cdNotify(@RequestParam("isAccurate") Boolean isAccurate, @RequestBody CdInfo cdInfo) {
        cdInfoService.cdNotify(cdInfo, isAccurate);
    }

    @PostMapping("/pullList")
    public void pullList(@RequestBody List<CdInfo> cdInfos) {
        cdInfoService.pullList(cdInfos);
    }

    @PostMapping("/pullOrder")
    public PullOrderResp pullOrder(@RequestBody List<OrderInfoReq> orderInfoReqs) {
        PullOrderResp resp = cdInfoService.pullOrder(orderInfoReqs);
        resp.setIsContinue(false);
        return resp;
    }

    @GetMapping("/getSmallAmount")
    public CdInfo getSmallAmount(@RequestParam("accountNumber") String accountNumber, @RequestParam("accountName") String accountName, @RequestParam("accountMoney") String accountMoney) {
        return cdInfoService.getSmallAmount(accountNumber, accountName, accountMoney);
    }

    @PostMapping("/submitCd")
    public ResponseData submitCd(@RequestBody SubmitCdReq submitCdReq) {
        cdInfoService.submitCd(submitCdReq);
        return ResponseData.success();
    }

}
